<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="生产订单号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'productOrdNo', validatorRules.productOrdNo]" placeholder="请输入生产订单号"></a-input>
        </a-form-item>
        <a-form-item label="生产订单物料编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'productOrdMatNo', validatorRules.productOrdMatNo]" placeholder="请输入生产订单物料编号"></a-input>
        </a-form-item>
        <a-form-item label="生产订单物料描述" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'productOrdMatDesc', validatorRules.productOrdMatDesc]" placeholder="请输入生产订单物料描述"></a-input>
        </a-form-item>
        <a-form-item label="序号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'serialNo', validatorRules.serialNo]" placeholder="请输入序号"></a-input>
        </a-form-item>
        <a-form-item label="BOM物料编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'bomMaterialNo', validatorRules.bomMaterialNo]" placeholder="请输入BOM物料编码"></a-input>
        </a-form-item>
        <a-form-item label="BOM物料描述" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'bomMaterialDesc', validatorRules.bomMaterialDesc]" placeholder="请输入BOM物料描述"></a-input>
        </a-form-item>
        <a-form-item label="BOM物料数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'bomCount', validatorRules.bomCount]" placeholder="请输入BOM物料数量" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="BOM物料单位" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'bomUnit', validatorRules.bomUnit]" placeholder="请输入BOM物料单位"></a-input>
        </a-form-item>
        <a-form-item label="供应商编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'supplierCode', validatorRules.supplierCode]" placeholder="请输入供应商编号"></a-input>
        </a-form-item>
        <a-form-item label="1：未读（默认状态）
0：成功；" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'ioflag', validatorRules.ioflag]" placeholder="请输入1：未读（默认状态）
0：成功；"></a-input>
        </a-form-item>
        <a-form-item label="tid" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'tid', validatorRules.tid]" placeholder="请输入tid" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="工艺编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'processRouteNo', validatorRules.processRouteNo]" placeholder="请输入工艺编号"></a-input>
        </a-form-item>
        <a-form-item label="检测时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择检测时间" v-decorator="[ 'updateTime', validatorRules.updateTime]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'  
  
  export default {
    name: "ZxjEip_2cScbomModal",
    components: { 
      JDate,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        productOrdNo:{rules: [{ required: true, message: '请输入生产订单号!' }]},
        productOrdMatNo:{rules: [{ required: true, message: '请输入生产订单物料编号!' }]},
        productOrdMatDesc:{rules: [{ required: true, message: '请输入生产订单物料描述!' }]},
        serialNo:{rules: [{ required: true, message: '请输入序号!' }]},
        bomMaterialNo:{rules: [{ required: true, message: '请输入BOM物料编码!' }]},
        bomMaterialDesc:{rules: [{ required: true, message: '请输入BOM物料描述!' }]},
        bomCount:{rules: [{ required: true, message: '请输入BOM物料数量!' }]},
        bomUnit:{rules: [{ required: true, message: '请输入BOM物料单位!' }]},
        supplierCode:{rules: [{ required: true, message: '请输入供应商编号!' }]},
        ioflag:{rules: [{ required: true, message: '请输入1：未读（默认状态）0：成功；!' }]},
        tid:{rules: [{ required: true, message: '请输入tid!' }]},
        processRouteNo:{},
        updateTime:{},
        },
        url: {
          add: "/ZxjEip2cScbom/zxjEip_2cScbom/add",
          edit: "/ZxjEip2cScbom/zxjEip_2cScbom/edit",
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'productOrdNo','productOrdMatNo','productOrdMatDesc','serialNo','bomMaterialNo','bomMaterialDesc','bomCount','bomUnit','supplierCode','ioflag','tid','processRouteNo','updateTime'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'productOrdNo','productOrdMatNo','productOrdMatDesc','serialNo','bomMaterialNo','bomMaterialDesc','bomCount','bomUnit','supplierCode','ioflag','tid','processRouteNo','updateTime'))
      }
      
    }
  }
</script>